home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qgarray.h.z / qgarray.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  2.8 KB  |  103 lines

  1. /****************************************************************************
  2. ** $Id: qgarray.h,v 2.4 1998/07/03 00:09:44 hanord Exp $
  3. **
  4. ** Definition of QGArray class
  5. **
  6. ** Created : 930906
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QGARRAY_H
  25. #define QGARRAY_H
  26.  
  27. #ifndef QT_H
  28. #include "qshared.h"
  29. #endif // QT_H
  30.  
  31.  
  32. class QGArray                    // generic array
  33. {
  34. friend class QBuffer;
  35. public:
  36.     struct array_data : public QShared {    // shared array
  37.     array_data()    { data=0; len=0; }
  38.     char *data;                // actual array data
  39.     uint  len;
  40.     };
  41.     QGArray();
  42. protected:
  43.     QGArray( int, int );            // dummy; does not alloc
  44.     QGArray( int size );            // allocate 'size' bytes
  45.     QGArray( const QGArray &a );        // shallow copy
  46.     virtual ~QGArray();
  47.  
  48.     QGArray    &operator=( const QGArray &a ) { return assign( a ); }
  49.  
  50.     virtual void detach()    { duplicate(*this); }
  51.  
  52.     char       *data()     const    { return shd->data; }
  53.     uint    nrefs()     const    { return shd->count; }
  54.     uint    size()     const    { return shd->len; }
  55.     bool    isEqual( const QGArray &a ) const;
  56.  
  57.     bool    resize( uint newsize );
  58.  
  59.     bool    fill( const char *d, int len, uint sz );
  60.  
  61.     QGArray    &assign( const QGArray &a );
  62.     QGArray    &assign( const char *d, uint len );
  63.     QGArray    &duplicate( const QGArray &a );
  64.     QGArray    &duplicate( const char *d, uint len );
  65.     void    store( const char *d, uint len );
  66.  
  67.     array_data *sharedBlock()    const        { return shd; }
  68.     void    setSharedBlock( array_data *p ) { shd=(array_data*)p; }
  69.  
  70.     QGArray    &setRawData( const char *d, uint len );
  71.     void    resetRawData( const char *d, uint len );
  72.  
  73.     int        find( const char *d, uint index, uint sz ) const;
  74.     int        contains( const char *d, uint sz ) const;
  75.  
  76.     char       *at( uint index ) const;
  77.  
  78.     bool    setExpand( uint index, const char *d, uint sz );
  79.  
  80. protected:
  81.     virtual array_data *newData()            { return new array_data; }
  82.     virtual void    deleteData( array_data *p ) { delete p; }
  83.  
  84. private:
  85.     static void msg_index( uint );
  86.     array_data *shd;
  87. };
  88.  
  89.  
  90. inline char *QGArray::at( uint index ) const
  91. {
  92. #if defined(CHECK_RANGE)
  93.     if ( index >= size() ) {
  94.     msg_index( index );
  95.     index = 0;
  96.     }
  97. #endif
  98.     return &shd->data[index];
  99. }
  100.  
  101.  
  102. #endif // QGARRAY_H
  103.